/**Room class
 * 
 * @author locphan
 * @version 1.01
 */
import java.util.Calendar;


public class Room
{
   private int capacity;
   private MonthlySchedule[] monthlyschedule;
   private final int MONTHS_IN_A_YEAR = 12;
   
   /**Creats a room with capacity
    * 
    * @param capacity
    */
   public Room(int capacity)
   {
      this.capacity = capacity;
      monthlyschedule = new MonthlySchedule[MONTHS_IN_A_YEAR];
   }   
   /**Add a request to this room
    * 
    * @param r a Request
    * @return true if request is added
    *         false otherwise
    */
   public boolean add(Request r)
   {
      
      int month = r.getDate().get(Calendar.MONTH);
      boolean result = false;
      
      if(monthlyschedule[month]==null)
      {
         monthlyschedule[month] = new MonthlySchedule();
         monthlyschedule[month].add(r);
      }
      else
      {
        result = monthlyschedule[month].add(r);      
      }
      return result;
   }
   /**Return capacity of the room
    * 
    * @return capacity
    */
   public int getCapacity()
   {
      return capacity;
   }
   /**Cancels a request
    * 
    * @param r a Request
    * @return true if request is canceled
    *           false otherwise
    */
   
   public boolean cancel(Request r)
   {
      int month = r.getDate().get(Calendar.MONTH);

      boolean result = false;
      
      if(monthlyschedule[month]==null)
      {
         result = false;
      }
      else
      {
        result = monthlyschedule[month].cancel(r.getName());
        
      }
      return result;
   }
   /**Return a string representation of a month
    * 
    * @param month month
    * @return monthly schedule
    */
   public String printMonthlySchedule(int month)
   {     
      String result = "";
      if(monthlyschedule[month] == null)
      {result = "";}
      else
      {result = monthlyschedule[month].toString();} 
      return result;
   }
   /**Return a string representation of this room
    * 
    */
   public String toString()
   {
      String result = "";
      for(int i=0;i<MONTHS_IN_A_YEAR;i++)
      {
         if(monthlyschedule[i]==null)
         {}
         else
         {
            result += monthlyschedule[i].toString();
         }
         
      }
      return result;

   }
}
